package com.cdp.zwy.background_manager_back.exception;

import com.cdp.zwy.background_manager_back.common.Result;
import com.cdp.zwy.background_manager_back.common.CustomException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Administrator
 * @version 1.0
 * @description: 全局异常处理
 * @date 2025/3/26 10:44
 */
//捕获controller里的所有异常
@ControllerAdvice("com.cdp.zwy.background_manager_back.controller")
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.error();
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Result error(CustomException e){

        return Result.error(e.getCode(),e.getMsg());
    }


}

